import { Tree } from '@angular-devkit/schematics';
import { SchematicTestRunner } from '@angular-devkit/schematics/testing';
import * as path from 'path';
import { getContent } from './utils/test-utils';

const collectionPath = path.join(__dirname, '../collection.json');

describe('测试state生成结果', () => {
  it('system', async () => {
    const runner = new SchematicTestRunner('state', collectionPath);
    const tree = await runner.runSchematic('state',
        {name: 'system', path: '/testA'}, Tree.empty());
    expect(tree.get('/testA/system/system.action.ts')?.content.toString()).toEqual(getContent('src/state/tests/system.action.ts.txt'));
    expect(tree.get('/testA/system/system.state.ts')?.content.toString()).toEqual(getContent('src/state/tests/system.state.ts.txt'));
    expect(tree.get('/testA/system/system.selector.ts')?.content.toString()).toEqual(getContent('src/state/tests/system.selector.ts.txt'));
  });
  it('user', async () => {
    const runner = new SchematicTestRunner('state', collectionPath);
    const tree = await runner.runSchematic('state',
        {name: 'user', path: '/testA'}, Tree.empty());
    expect(tree.get('/testA/user/user.action.ts')?.content.toString()).toEqual(getContent('src/state/tests/user.action.ts.txt'));
    expect(tree.get('/testA/user/user.state.ts')?.content.toString()).toEqual(getContent('src/state/tests/user.state.ts.txt'));
    expect(tree.get('/testA/user/user.selector.ts')?.content.toString()).toEqual(getContent('src/state/tests/user.selector.ts.txt'));
  });
  it('测试生成带路径的', async () => {
    const runner = new SchematicTestRunner('state', collectionPath);
    const tree = await runner.runSchematic('state',
        {name: 'test1/test2/test3/user', path: '/testA'}, Tree.empty());
    expect(tree.get('/testA/test1/test2/test3/user/user.action.ts')?.content.toString()).toEqual(getContent('src/state/tests/user.action.ts.txt'));
    expect(tree.get('/testA/test1/test2/test3/user/user.state.ts')?.content.toString()).toEqual(getContent('src/state/tests/user.state.ts.txt'));
    expect(tree.get('/testA/test1/test2/test3/user/user.selector.ts')?.content.toString()).toEqual(getContent('src/state/tests/user.selector.ts.txt'));
  });
});
